﻿using System;
using System.Collections.Generic;
using EzDesk.Apps.Model.Attendance;

namespace EzDesk.Apps.ServiceImpl.Attendance.Evaluation
{
    public sealed class SimpleDayAttendanceEvaluator: DayAttendanceEvaluatorBase
    {
        private DayLeaveInfo _dayLeaveInfo;
        private LateAndEarlyMins _lateAndEarly;

        public SimpleDayAttendanceEvaluator(
            DayInfo dayInfo,
            AttendanceConfig config,
            List<AttendanceInfo> attendanceInfoList
            )
        {
            if (attendanceInfoList == null)
            {
                attendanceInfoList = new List<AttendanceInfo>();
            }

            Config = config;
            AttendanceInfoList = attendanceInfoList;
            DayInfo = dayInfo;

            _lateAndEarly = CalculateLateAndEarlyMinutes();
        }

        public override DayAttendanceEvaluation GetAttendanceEvaluation()
        {
            // 初始化对象
            var resultEvaluationInfo = new DayAttendanceEvaluation
                                           {
                                               Id = Guid.Empty,
                                               Date = DayInfo.Date,
                                               IsNeedToWork = DayInfo.IsNeedToWork,
                                               LateMiniutes = _lateAndEarly.LateMiniutes,
                                               EarlyMiniutes = _lateAndEarly.EarlyMiniutes,
                                               Manhours = CalculateManhours(),
                                               IsAbsense = IsAbsenseToday(),
                                               IsExtraWork = IsExtraWorkToday(),
                                               LeaveInfo = _dayLeaveInfo,
                                           };
            return resultEvaluationInfo;
        }
    }
}